package com.runchinaup.runchilibrary.upg;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.runchinaup.runchilibrary.R;


/**
 * Created by nopointer on 2016/10/16.
 */
public class DownloadProgressDialog extends Dialog {

    protected Context mContext;

    public DownloadProgressDialog(Context context) {
        super(context, R.style.dialog_style);
        this.mContext = context;
    }

    private TextView progress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_down_progress);
        progress = (TextView) findViewById(R.id.progress);
        ((Button) findViewById(R.id.cancel_btn)).setText(R.string.cancel);
        findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancel();
                onLeftClick();
            };
        });
        findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onRightClick();
            }
        });
    }

    public void onLeftClick() {
    }

    public void onRightClick() {

    }

    public void updataPro(final String pro) {
        ((Activity) mContext).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                progress.setText(pro);
            }
        });
    }

    public DownloadProgressDialog showDialog() {
        show();
        return this;
    }

    public void updataPro(final int pro) {
        ((Activity) mContext).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                progress.setText(pro);
            }
        });
    }
}
